//
//  HomeZhaopinViewController.m
//  shuiyun
//
//  Created by 徐双 on 2017/9/8.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "HomeZhaopinViewController.h"
#import "HomeZhaoQiuViewCell.h"
#import "HomeZhaoDetailViewController.h"

@interface HomeZhaopinViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@property(nonatomic,strong)NSMutableArray * dataArr;


@end

@implementation HomeZhaopinViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self HomeZhaoData];
   
    //初始化tableView
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64);
    
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //   self.tableView.estimatedRowHeight = 400;
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去掉分割线
    
    
    [self.view addSubview:self.tableView];
    self.view.backgroundColor = [UIColor colorWithRed:245 / 255.0f green:245 / 255.0f blue:245 / 255.0f alpha:1];
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"HomeZhaoQiuViewCell" bundle:nil] forCellReuseIdentifier:@"HomeZhaoQiuViewCell"];

}

-(void)HomeZhaoData{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication]keyWindow] animated:YES];
    hud.tag = 500;
    //提示文本
    hud.labelText = @"正在加载...";
    //是否有遮罩
    hud.dimBackground = YES;
    _dataArr = [NSMutableArray array];

    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    [productParams setValue:token forKey:@"token"];
    NSString * userid = [PublicFunction getConfigWithKey:@"userid"];
    [productParams setValue:userid forKey:@"userid"];
    
    
    
    [[MNetworkHandler sharedInstance]conURL:HomeZhaopin  networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        NSLog(@"%@", returnData);
        NSLog(@"%@", productParams);
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            _dataArr = [returnData objectForKey:@"data"];
            NSLog(@"!!!!!!!!!!!!!!!%@",_dataArr);
            
            [self.tableView reloadData];
            
            [hud removeFromSuperview];
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            [hud removeFromSuperview];
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
        [hud removeFromSuperview];        
    }];
    

}

#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
    
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 100;
    
}

#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HomeZhaoQiuViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HomeZhaoQiuViewCell"];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSDictionary * dict = _dataArr[indexPath.row];
    
    cell.contentLabel.text = @"招聘岗位:";
    cell.nameLabelTitle.text = @"姓名:";
    cell.beizhuLabelTitle.text = @"工作经历:";
    cell.jobLabel.text = [dict objectForKey:@"z_zhiwei"];
    cell.nameLabel.text = [dict objectForKey:@"z_lian"];
    cell.experienceLabel.text = [dict objectForKey:@"z_conter"];
    
    return cell;
    
}
#pragma mark - ---------- 每个Cell的点击事件 ----------
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomeZhaoDetailViewController * vc = [[HomeZhaoDetailViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    NSDictionary * dict = self.dataArr[indexPath.row];
    vc.idStr = [dict objectForKey:@"id"];
    
    [self.navigationController pushViewController:vc animated:YES];
    
}



@end
